using SqlSugar;
using IM.Easy.Core.Audit;
using System.ComponentModel;

namespace IM.Easy.Entity.System
{
    /// <summary>
    /// 组织和部门结构表
    /// </summary>
    [SugarTable("SysDepartment")]
    public class SysDepartment : AuditSnowflakeEntity, IOrderable, IActive, ISystem
    {
        public SysDepartment()
        {
            IsActive = true;
        }
        /// <summary>
        /// 联系电话
        /// </summary>
        [SugarColumn(ColumnName = "Mobile")]
        public string? Mobile { get; set; }

        /// <summary>
        /// 组织单位编号，用于唯一标识
        /// </summary>
        [SugarColumn(ColumnName = "Code")]
        public string Code { get; set; }

        /// <summary>
        /// 组织单位类型 常量类型 OrgTypeConstant
        /// </summary>
        [SugarColumn(ColumnName = "Type")]
        public string? Type { get; set; }

        /// <summary>
        /// 联系邮箱
        /// </summary>
        [SugarColumn(ColumnName = "Email")]
        public string? Email { get; set; }

        /// <summary>
        /// 组织单位名称
        /// </summary>
        [SugarColumn(ColumnName = "Name")]
        public string Name { get; set; }

        /// <summary>
        /// 描述信息
        /// </summary>
        [SugarColumn(ColumnName = "Desc")]
        public string? Desc { get; set; }

        /// <summary>
        /// 上级组织单位ID，自引用用于组织和部门的层级关系
        /// </summary>
        [SugarColumn(ColumnName = "ParentId")]
        public long ParentId { get; set; }

        /// <summary>
        /// 负责人ID（适用于部门经理或组织负责人）
        /// </summary>
        [SugarColumn(ColumnName = "ManagerId")]
        public long ManagerId { get; set; }
        public int Order { get; set; }
        public bool IsActive { get; set; }
        public bool IsSystem { get; set; }

        /// <summary>
        /// 叶子节点
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public List<SysDepartment> Children { get; set; }

        /// <summary>
        /// 父级节点
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(ParentId))]
        public SysDepartment Parent { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(CreatedBy))]
        public SysUser Creator { get; set; }

        /// <summary>
        /// 更新人
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(UpdatedBy))]
        public SysUser Updater { get; set; }

        /// <summary>
        /// 部门负责人
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(ManagerId))]
        public SysUser Manager { get; set; }
    }
}
